package goldeneagle.com.admin.servlet;

import com.alibaba.fastjson.JSONObject;
import goldeneagle.com.admin.service.AdminManagerService;
import goldeneagle.com.entity.Product;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/ShowProductServlet")
public class ShowProductServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String ids = request.getParameter("id");
        int id = Integer.parseInt(ids);
        AdminManagerService adminManagerService = new AdminManagerService();
        Product product = adminManagerService.findProductById(id);
        response.getWriter().write(JSONObject.toJSONString(product));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request,response);
    }
}
